import 'package:adXunfei/flutter_xunfei.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  FlutterXunfei _Xunfei;

  @override
  void initState() {
    super.initState();
    _Xunfei = FlutterXunfei.xunfei;
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
            child: ListView(
          children: <Widget>[
            RaisedButton(
              onPressed: () {
                _Xunfei.initIat(
                  appid: "5f11439d",
                  listener: XunfeiListener(
                    onResult: (value) {
                      print(value);
                    },
                  ),
                );
              },
              child: Text("创建讯飞语音识别服务"),
            ),
            RaisedButton(
              onPressed: () {
                _Xunfei.startIat(listener: XunfeiListener(onResult: (value) {
                  print("识别结果：");
                  print(value);
                  print("----------------");
                }));
              },
              child: Text("开始语音识别"),
            ),
            RaisedButton(
              onPressed: () {
                _Xunfei.stopIat();
              },
              child: Text("停止语音识别"),
            ),
            RaisedButton(
              onPressed: () {
                _Xunfei.cancelIat();
              },
              child: Text("取消语音识别"),
            ),
            SizedBox(height: 40),
            RaisedButton(
              onPressed: () {
                _Xunfei.initIvw(
                  appid: "5f11439d",
                  listener: XunfeiListener(
                    onResult: (value) {
                      print(value);
                    },
                  ),
                );
              },
              child: Text("创建语音唤醒服务"),
            ),
            RaisedButton(
              onPressed: () {
                _Xunfei.openIvw(listener: XunfeiListener(onResult: (value) {
                  print("识别结果：");
                  print(value);
                  print("----------------");
                  _Xunfei.closeIvw();
                }));
              },
              child: Text("开启语音唤醒"),
            ),
            RaisedButton(
              onPressed: () {
                _Xunfei.closeIvw();
              },
              child: Text("关闭语音唤醒"),
            ),
          ],
        )),
      ),
    );
  }
}
